<template>
	<view class="container">
		<view v-for="(item,index) in recordingData">
			<uni-card :title="item.xm" :sub-title="'所属组:'+item.deptname" :extra="'申请状态:'+item.zt" :thumbnail="avatar" @click="onClick">
				<text class="uni-body">
					申请时间：{{item.sj}}
				</text>
				<text class="uni-body" >体 位：{{item.tw}}</text>
				<text class="uni-body">担 架：{{item.dj}}</text>
				<text class="uni-body">说 明：{{item.bz}}</text>
				<button size="mini" style="background-color: #555500; color: #fff;" @click="overrule(item)">驳回</button>
				<button @click="evacuation(item)" size="mini" style="background-color: #555500; color: #fff; margin-left: 30rpx;">后送</button>
			</uni-card>
		</view>
        <uni-load-more :status="status" :contentText="contentText" />
		<!-- 驳回弹窗 -->
		<uni-popup ref="inputDialog" type="dialog">
			<uni-popup-dialog ref="inputClose"  mode="input" title="驳回原因"
				placeholder="请输入驳回原因" @confirm="dialogInputConfirm"></uni-popup-dialog>
		</uni-popup>
		<!-- 后送弹窗 -->
		<uni-popup ref="popup" background-color="#fff"  >
			<view class="popup-content" :class="{ 'popup-height': type === 'left' || type === 'right' }">
					<view class="example">
						<uni-forms ref="baseForm" :modelValue="baseFormData" label-width="100px">
							<uni-forms-item label="类型" class="wounded">
								<uni-data-checkbox style="margin-top: 10rpx;" v-model="baseFormData.lx" :localdata="lx" />
							</uni-forms-item>
							<uni-forms-item label="批次号" class="wounded">
								<uni-easyinput disabled="" v-model="baseFormData.pch"/>
							</uni-forms-item>
							<uni-forms-item label="方式" class="wounded">
								<uni-data-checkbox style="margin-top: 10rpx;" v-model="baseFormData.fs" :localdata="fs" />
							</uni-forms-item>
							<uni-forms-item label="送往" class="wounded">
								<uni-easyinput v-model="baseFormData.sw"/>
							</uni-forms-item>
							<uni-forms-item label="说明" class="wounded">
								<uni-easyinput type="textarea" v-model="baseFormData.bz"/>
							</uni-forms-item>
						</uni-forms>
					</view>
					<view class="fixedBottom">
						<button class="trueDecide" @click="trueDecide()">确定</button>
						<button class="cancel" @click="cancel()">取消</button>
					</view>
			</view>
		</uni-popup>
	</view>
</template>
<script>
	import { evacuationManage,dictionary,lotNumber, evacuationConfirm, overrule } from '../../api/huanzhe.js'
	import { useRouter,toast } from '../../utils/utils.js'
	export default {
		data() {
			return {
				recordingData:[],
				status: 'more',
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '我也是有底线的~'
				},
				InquireData:{
					pageNum:1,
					pageSize: 20
				},
				id:null,
				bh:[],
				baseFormData:{},
				fs:[],
				lx:[]
			}
		},
		onReachBottom(e){
			this.status = 'loading'
			this.InquireData.pageNum++;
			this.evacuationManages()
		},
		onLoad(){
			this.evacuationManages()
			this.manner()
			this.typeInjure()
		},
		methods: {
			cancel(){
				this.$refs.popup.close()
			},
			trueDecide(){
				var query={
					bz:this.baseFormData.bz,
					fs:this.baseFormData.fs,
					lx:this.baseFormData.lx,
					pch:this.baseFormData.pch,
					sw:this.baseFormData.sw,
					cqhsId:[this.id]
				}
				console.log(query);
				evacuationConfirm(query).then(res=>{
					console.log(res);
					if(res.cede==200){
						this.evacuationManages()
						toast("后送成功")
						this.baseFormData={}
						this.$refs.popup.close()
					}else{
						this.evacuationManages()
						toast("后送失败")
						this.baseFormData={}
						this.$refs.popup.close()
					}
				})
			},
			// 方式查询
			manner(){
				dictionary('weiqin_housong_fangshi').then(res=>{
					res.data.forEach((item,index)=>{
						var fs={
							value:item.dictValue,
							text:item.dictLabel
						}
						this.fs.push(fs)
					})
				})
			},
			// 类型查询
			typeInjure(){
				dictionary('weiqin_housong_leixing').then(res=>{
					res.data.forEach((item,index)=>{
						var lx={
							value:item.dictValue,
							text:item.dictLabel
						}
						this.lx.push(lx)
					})
				})
			},
			// 批次号查询
			lotNumbers(){
				lotNumber().then(res=>{
					this.baseFormData.pch=(parseInt(res.data)+1);
				})
			},
			// 驳回确认
			dialogInputConfirm(e){
				var bh={
					id:this.id,
					bhyy:e
				}
				this.bh.push(bh)
				overrule(this.bh).then(res=>{
					if(res.code===200){
						this.evacuationManages()
						toast("驳回成功")
					}else{
						this.evacuationManages()
						toast("驳回失败")
					}
				})
			},
			evacuation(item){
				this.id=item.id
				this.$refs.popup.open('bottom')
				this.lotNumbers()
			},
			evacuationManages(){
				evacuationManage(this.InquireData).then(res=>{
					if (!res.rows.length) {
						this.status = 'no-more'
					} else {
						this.status = 'more'
					}
					if (this.recordingData.length) {
						this.recordingData.push(...res.rows)
					} else {
						console.log(res.rows);
						this.recordingData = res.rows
					}
				})
			},
			overrule(item){
				this.id=item.id
				this.$refs.inputDialog.open()
			},
			nursingDetail(item){
				useRouter('/pages/evacuation/detailEvacuation',{
					xm:item.xm,
					ssz:item.deptname,
					sj:item.sj,
					tw:item.tw,
					dj:item.dj,
					bz:item.bz,
					zt:item.zt,
					id:item.id
				},'navigateTo')
			}
		}
	}
</script>
<style lang="scss">
	.uni-body{
		display:block
	}
	::v-deep.uni-section .uni-section-header__decoration{
	    margin-right: 6px;
	    background-color: #23440d;
	}
		.popup-content {
			align-items: center;
			justify-content: center;
			padding: 15px;
			height: 900rpx;
			background-color: #fff;
		}
	
		.popup-height {
			width: 500px;
		}
	.fixedBottom{
			height: 200rpx;
			background-color: #FFF;
			position: fixed;
			bottom: 0rpx;
			left: 0;
			right: 0;
			display: flex;
			align-items: center;
			justify-content: space-between;
			z-index: 50;
			button{
				width: 300rpx;
				height: 88rpx;
				color: white;
				background-color: #ffaa00;
				border-radius: 20px;
				line-height: 88rpx;
				text-align: center;
			}
		}
</style>